package priv.books.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import priv.books.mapper.UserMapper;
import priv.books.pojo.Admin;
import priv.books.pojo.User;
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询所有信息
     *
     * @param user
     * @return
     */
//    public List<User> getAllInfo(User user) {
//        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
//        return userMapper.selectList(queryWrapper);
//    }
    public List<User> getAllInfo(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (user != null) {
            queryWrapper.like(!StrUtil.isBlankOrUndefined(user.getUserName()), "user_name", user.getUserName());
        }
        return userMapper.selectList(queryWrapper);
    }

    /**
     * 查询登录信息
     *
     * @param user
     * @return
     */
    public User getLoginInfo(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("user_name", user.getUserName());
        queryWrapper.eq("password", user.getPassword());
        return userMapper.selectOne(queryWrapper);
    }
}

